package com.gome.ocean;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.StringWriter;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang3.StringEscapeUtils;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Base64Utils;

import com.beust.jcommander.internal.Lists;
import com.gome.framework.base.BaseTest;
import com.gome.framework.util.DateUtil;
import com.gome.framework.util.SystemInfoUtil;
import com.gome.ocean.common.constants.VelocityContants;
import com.gome.ocean.common.utils.CompressFileUtils;
import com.gome.ocean.common.utils.StringEscapeUtil;
import com.gome.ocean.dao.model.datasource.SQLUploadBean;
import com.gome.ocean.service.datax.ISQLUploadService;
import com.gome.ocean.service.mail.EmailSubject;
import com.gome.ocean.service.mail.SimpleMailSender;
import com.gome.ocean.service.velocity.VelocityBean;
import com.google.common.collect.Maps;

/**
 * @author zhangguoqing 2016年12月29日 下午5:40:33
 * @since 5.0.0
 */
public class CompressTestUtils extends BaseTest {

    @Autowired
    private SimpleMailSender  simpleMailSender;
    @Autowired
    private ISQLUploadService uploadService;
    @Autowired
    private VelocityBean      velocityBean;

    @org.testng.annotations.Test
    public void test1() {
        // File file = new File("E:\\testB.zip");
        String abc = "INSERT INTO tb_category('uid','cate_name')" + "\r\n" + "VALUES('1','hello'),('2','tar');";
        // try {
        // CompressUtils.compressByteFile(file, abc.getBytes(), "UTF-8", "TEST",
        // ".sql");
        // } catch (FileNotFoundException e) {
        // e.printStackTrace();
        // }

        Map<String, Object> map = Maps.newHashMap();
        map.put("id", 69);
        SQLUploadBean sqlBean = uploadService.getBeanByMap(map);
        // byte[] fileBt = Base64Utils.decodeFromString(sqlBean.getSqlFile());
        // File file = CompressFileUtils.byteToFile("E:\\", sqlBean.getFiles(),
        // fileBt);
        // List<String> recipients = Lists.newArrayList();
        // recipients.add("zhangguoqing@gomeplus.com");
        // Map<String, Object> paramMaps = new HashMap<String, Object>();
        // paramMaps.put("submitUser", "zhangguoqing@gomeplus.com");
        //
        // paramMaps.put("executeSQL", "文本内容:" + abc + "<br/> 附件内容:" +
        // sqlBean.getFiles());
        // paramMaps.put("submitTime", DateUtil.format(new Date(), "yyyy-MM-dd
        // HH:mm:ss"));
        // String authorityContent =
        // velocityBean.assemblePlugins(VelocityContants.AUTHORITY_MAIL,
        // paramMaps);
        // simpleMailSender.sendContentAndFileEmail(recipients,
        // EmailSubject.SQLAUTHORITY, authorityContent, file);
        // System.out.println(file.getPath());
        String text = sqlBean.getSqlText();

        String g = StringEscapeUtils.escapeJava(text);
        String d = StringEscapeUtils.escapeEcmaScript(text);
        String f = StringEscapeUtil.escapeJavaScript(text);
        System.out.println(g);
        System.out.println(d);
        System.out.println(f);
    }
}
